home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 36 / Amiga Format CD36 (1999-01-22)(Future Publishing)(GB)[!][issue 1999-02].iso / -websites- / amosfactory / downloads / gui170.lha / AmosIRC.Amos / AmosIRC.amosSourceCode next >
AMOS Source Code  |  1998-03-29  |  6KB  |  238 lines

  1. '**
  2. '**      $VER: AMOSPro IRC Client (17-10-97)     
  3. '**      Release 1.0   
  4. '**
  5. '**      A (very...) simple IRC client 
  6. '**
  7. '**      ï¿½ Copyright 1997 Pietro Ghizzoni - Dairymen Soft
  8. '**        FreeWare      
  9. '**
  10.  
  11. Set Buffer 30
  12. Amos To Back : Dim MSG$(200),USER$(50)
  13.  
  14. Global MSG$(),HOST$,USER$,L$,P$,C$,COM,MSG,MSGA,SRV$,NAME$,PW$,NICK$,SPK,USER$()
  15. Global TP$,USER,PAR$
  16.  
  17. 'Obtain the HOST and USER names    
  18. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. HOST$= Extension_24_0954("ENV:HOSTNAME") : USER$= Extension_24_0954("ENV:USERNAME")
  20. L$=Chr$(13)+Chr$(10) : MSGA=Array(MSG$(0)) : Extension_24_0018 1,1,20
  21.  
  22. 'Server and User settings
  23. '~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. If Exist("ENV:AmosIRC.prefs")
  25.    
  26.    Open In 2,"ENV:AmosIRC.prefs" : Input #2,NAME$,NICK$,SRV$,PW$ : Close 2
  27.    
  28. Else 
  29.    
  30.    PREFS
  31.    
  32. End If 
  33.  
  34. 'Open the connection and LOG file
  35. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  36. DISPLAY["AmosIRC | Connecting to "+SRV$]
  37. IRC= Extension_24_0C9C(1,SRV$+"/6667") : Open Out 1,"bbs:AmosIRC.log"
  38.  
  39. If IRC
  40.    
  41.    '**   User Registration   ** 
  42.    
  43.    If Len(PW$) : A= Extension_24_0B04(1,"PASS "+PW$+L$) : End If 
  44.    A= Extension_24_0B04(1,"NICK "+NICK$+L$)
  45.    A= Extension_24_0B04(1,"USER "+USER$+" "+HOST$+" "+SRV$+" :"+NAME$+L$)
  46.    
  47. Else 
  48.    
  49.    A= Extension_24_0150("AmosIRC","Unable to open the connection!","Uh?") : Goto _END
  50.    
  51. End If 
  52.  
  53. 'Enable the automatic data check 
  54. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. CHK= Extension_24_0C06(1,0,0)
  56.  
  57. 'This is the main loop.... simple eh? :) 
  58. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  59. Do 
  60.    
  61.    CD= Extension_24_0034 : G$= Extension_24_0060 
  62.    
  63.    If CD=-9
  64.       
  65.       If Extension_24_0B56 =CHK : Rem   We have received a signal! 
  66.          
  67.          If Extension_24_0B46 =0
  68.             _VIEW : If COM=375 : A= Extension_24_0B04(1,"JOIN #AMOS"+L$) : End If 
  69.          Else 
  70.             A= Extension_24_0150("AmosIRC","Connection lost!","Uh?") : Exit 
  71.          End If 
  72.          
  73.       End If 
  74.       
  75.    Else If CD=1
  76.       
  77.       'Send your message to the IRC channel
  78.       '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79.       A= Extension_24_0C32(1,":"+NICK$+" PRIVMSG #AMOS :"+G$+L$,0) : DISPLAY[NICK$+" | "+G$]
  80.       
  81.    Else If CD=-1
  82.       
  83.       A= Extension_24_0B04(1,"QUIT :Amiga RULEZ!"+L$) : Exit : Rem Bye, Bye #AMOS.... 
  84.       
  85.    Else If CD=4
  86.       
  87.       TP$=G$ : A= Extension_24_0C32(1,":"+NICK$+" TOPIC #AMOS :"+G$+L$,0)
  88.       
  89.    End If 
  90.    
  91. Loop 
  92.  
  93. _END: Close : Extension_24_0130 : Extension_24_0ADA 
  94.  
  95. Procedure _VIEW
  96.    
  97.    MSG : M$=Param$ : If M$="" Then Pop Proc
  98.    
  99.    If P$=SRV$
  100.       S$="Server"
  101.    Else 
  102.       C=Instr(P$,"!",1)-1 : If C=-1 : C=Instr(P$," ",1)-1 : End If 
  103.       S$=Mid$(M$,2,C) : Rem Obtain the sender NICK 
  104.    End If 
  105.    
  106.    L=Len(M$)-(Instr(M$,":",2)+1) : ME$=Right$(M$,L+1) : Rem Length of the message
  107.    
  108.    If C$="PRIVMSG"
  109.       
  110.        Extension_24_038C 
  111.       
  112.    Else If C$="JOIN"
  113.       
  114.       ME$=S$+" has joined  this channel" : USER[S$,1] : S$="Server"
  115.       
  116.    Else If C$="PART"
  117.       
  118.       ME$=S$+" has left this channel" : USER[S$,-1] : S$="Server"
  119.       
  120.    Else If C$="TOPIC" or COM=332
  121.       
  122.       TP$=ME$ : Extension_24_009E 1,4,0,Varptr(TP$)
  123.       If C$="TOPIC" : ME$=S$+" has changed the topic to "+ME$ : S$="Server" : End If 
  124.       
  125.    Else If COM=353
  126.       
  127.       USER[ME$,0] : Pop Proc
  128.       
  129.    Else If C$="MODE"
  130.       
  131.       Pop Proc
  132.       
  133.    End If 
  134.    
  135.    DISPLAY[S$+"  | "+ME$]
  136.    
  137.    
  138. End Proc
  139. Procedure MSG
  140.    
  141.    'Read the IRC commands line
  142.    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  143.    M$= Extension_24_0BE4(1) : COM=0 : Print #1,M$
  144.    
  145.    If Asc(M$)=58
  146.       
  147.       S=Instr(M$," ",2)+1 : P$=Mid$(M$,2,S-3) : Rem     PREFIX 
  148.       S1=Instr(M$," ",S) : C$=Mid$(M$,S,S1-S) : Rem     COMMAND (ASCII)
  149.       COM=Val(C$) : Rem                                 COMMAND (VALUE)
  150.       
  151.    Else 
  152.       
  153.       'Handle the server PING/PONG authentication  
  154.       '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  155.       If Left$(M$,4)="PING" : A= Extension_24_0C32(1,"PONG "+SRV$+L$,0) : End If : M$=""
  156.       
  157.    End If 
  158.    
  159.    If C$="PRIVMSG" : S=Instr(M$," ",S1+1) : PAR$=Mid$(M$,S1+1,S-S1-1) : End If 
  160.    
  161. End Proc[M$]
  162. Procedure DISPLAY[A$]
  163.    
  164.    If MSG=201 : Extension_24_09F0 MSGA,0 : MSG=200 : End If 
  165.    MSG$(MSG)=A$ : Inc MSG : Extension_24_009E 1,0,1,MSGA : Extension_24_009E 1,0,2,MSG
  166.    
  167. End Proc
  168. Procedure PREFS
  169.    
  170.    Dim EFN$(11) : Restore SERVERS : For I=0 To 11 : Read EFN$(I) : Next 
  171.     Extension_24_0006 2,2 : Extension_24_03B6 2 : Extension_24_009E 2,6,1,Array(EFN$(0))
  172.    
  173.    Repeat 
  174.       
  175.       GAD= Extension_24_0034 : CD= Extension_24_0052 : C$= Extension_24_0060 
  176.       
  177.       If GAD=4
  178.          
  179.          SRV$= Extension_24_037A(2,1) : NAME$= Extension_24_037A(2,0) : NICK$= Extension_24_037A(2,2)
  180.          PW$= Extension_24_037A(2,3) : PRF$=NAME$+L$+NICK$+L$+SRV$+L$+PW$+L$
  181.           Extension_24_0944 "ENV:AmosIRC.prefs",PRF$ : Extension_24_0944 "ENVARC:AmosIRC.prefs",PRF$
  182.          Exit 
  183.          
  184.       Else If GAD=5
  185.          
  186.          Exit 
  187.          
  188.       Else If GAD=6
  189.          
  190.          A=Instr(C$,"-",1)+1 : A$=Right$(C$,Len(C$)-A) : Extension_24_009E 2,1,0,Varptr(A$)
  191.          
  192.       End If 
  193.       
  194.    Until GAD=-1
  195.    
  196.     Extension_24_03C6 : A= Extension_24_0042(2)
  197.    
  198.    SERVERS:
  199.    Data "Germany - irc.uni-paderborn.de"
  200.    Data "USA - irc.stealth.net"
  201.    Data "USA - irc.colorado.edu"
  202.    Data "Finland - irc.funet.fi"
  203.    Data "Italy - irc.ccii.unipi.it"
  204.    Data "Italy - irc.flashnet.it"
  205.    Data "Israel - irc.tau.ac.il"
  206.    Data "Japan - irc.tokyo.wide.ad.jp"
  207.    Data "Australia - yoyo.cc.monash.edu.au"
  208.    Data "Belgium - othello.ulb.ac.be"
  209.    Data "Denmark - alk.iesd.auc.dk"
  210.    Data "France - sil.polytechnique.fr"
  211.    
  212. End Proc
  213. Procedure USER[A$,M]
  214.    
  215.    If M=0
  216.       
  217.       Do 
  218.          
  219.          A=Instr(A$,"@",B) : B=Instr(A$," ",A)
  220.          
  221.       If A>0 : USER$(USER)=Mid$(A$,A+1,B-A-1) : Inc USER Else Exit : End If 
  222.          
  223.       Loop 
  224.       
  225.       
  226.    Else If M=1
  227.       
  228.       USER$(USER)=A$ : Inc USER
  229.       
  230.    Else If M=-1
  231.       
  232.       For I=0 To USER : If USER$(I)=A$ : USER$(I)="" : End If : Next 
  233.       
  234.    End If 
  235.    
  236.     Extension_24_009E 1,2,1,Array(USER$(0))
  237.    
  238. End Proc